def chka(c):
    l = c
    for i in range(2, c-1, 1):
        if (c / i == int(c/i)): 
            l=i
    if l == c:
        return l
    else:
        return 0
    
a = int(input(""))

if (a >= 1000 and a <=9999 and a == int(a)):
    pshlnh = 0
    if chka(a): 
        pshlnh = a
    else:
      k1 = int(a/1000)
      k2 = int(a/100-k1*10)
      k3 = int(a/10-k1*100-k2*10)
      k4 = int(a-k1*1000-k2*100-k3*10)
      
      if chka(k1*10+k2)>pshlnh:
          pshlnh = k1*10+k2

      if chka(k2*10+k3)>pshlnh:
          pshlnh = k2*10+k3

      if chka(k3*10+k4)>pshlnh:
          pshlnh = k3*10+k4

      if chka(k1*100+k2*10+k3)>pshlnh:
          pshlnh = k1*100+k2*10+k3

      if chka(k2*100+k3*10+k4)>pshlnh:
          pshlnh = k2*100+k3*10+k4

    print(pshlnh)
else:
    print(0)